import { createRouter, createWebHashHistory } from "vue-router";
import authGuard from "@/router/authGuard";

//底部标签页面
const Home = () => import("../views/home/Home.vue");
const Contact = () => import("../views/contact/Contact");
const Sns = () => import("../views/sns/Sns");
//搜索页面
const UseSearch = () => import("@/components/search/searchPage");
//宠物发布页面
const PublishFrom = () => import("@/views/Publish/PublishFrom");
//作者集页面  -------
const AuthorTable = () => import("../views/authorTable/authorTable");
const AuthorDetails = () => import("../views/authorTable/authorDetails");
const DetailsEnvelop = () =>
  import("../views/authorTable/component/DetailsEnvelop");
const DetailsBookmark = () =>
  import("../views/authorTable/component/DetailsBookmark");
const DetailsStar = () => import("../views/authorTable/component/DetailsStar");
const DetailsLike = () => import("../views/authorTable/component/DetailsLike");
//-------
//宠物园页面
const PetTable = () => import("../views/petTable/petTable");
const DetailsPet = () => import("@/views/petTable/detailsPet");
//--------
// 我的页面
const User = () => import("../views/user/User");
// 个人资料页面
const UserInfo = () => import("../views/user/components/UserInfo");
const UserRegister = () => import("../views/user/components/UserRegister");
// 用户登录页面
const UserLogin = () => import("../views/user/components/UserLogin");
// 设置页面
const Setting = () => import("../views/user/components/Setting");
// 我的收藏页面
const Collect = () => import("../views/user/components/Collect");
// 我的发布页面
const UserPublish = () => import("../views/user/components/UserPublish");
// 我的领养页面
const UserAdopt = () => import("../views/user/components/UserAdopt");

// 论坛详情页面
const ForumDetails = () => import("@/views/sns/components/ForumDetails");
const PublishForum = () => import("@/views/sns/components/PublishForum");

const ContactTalk = () => import("@/views/contact/components/ContactTalk");

const routes = [
  {
    path: "/",
    name: "Home",
    component: Home,
  },
  {
    path: "/contact",
    name: "Contact",
    component: Contact,
  },
  {
    path: "/talk/:id/:name",
    component: ContactTalk,
  },
  {
    path: "/sns",
    name: "Sns",
    component: Sns,
  },
  {
    path: "/sns/details/:id",
    name: "ForumDetails",
    component: ForumDetails,
  },
  {
    path: "/publish/forum",
    name: "PublishForum",
    component: PublishForum,
  },
  {
    path: "/publish",
    name: "Publish",
    component: PublishFrom,
  },
  {
    path: "/useSearch",
    name: "UseSearch",
    component: UseSearch,
  },
  //作者集页面
  {
    path: "/authorTable",
    name: "AuthorTable",
    component: AuthorTable,
  },
  //作者详情页面
  {
    path: "/authorTable/:id",
    name: "AuthorDetails",
    component: AuthorDetails,
    children: [
      {
        path: "",
        component: DetailsBookmark,
      },
      {
        path: "bookmark",
        name: "DetailsBookmark",
        component: DetailsBookmark,
      },
      {
        path: "envelop",
        name: "DetailsEnvelop",
        component: DetailsEnvelop,
      },
      {
        path: "star",
        name: "DetailsStar",
        component: DetailsStar,
      },
      {
        path: "like",
        name: "DetailsLike",
        component: DetailsLike,
      },
    ],
  },
  //宠物园页面
  {
    path: "/petTable",
    name: "PetTable",
    component: PetTable,
  },
  //宠物详情页面
  {
    path: "/petTable/:id",
    name: "DetailsPet",
    component: DetailsPet,
  },
  // 我的页面
  {
    path: "/users",
    name: "User",
    component: User,
  },
  // 个人资料
  {
    path: "/user/userInfo",
    name: "UserInfo",
    component: UserInfo,
  },
  // 用户注册
  {
    path: "/register",
    name: "UserRegister",
    component: UserRegister,
  },
  // 用户登录
  {
    path: "/login",
    name: "UserLogin",
    component: UserLogin,
  },
  // 我的收藏
  {
    path: "/user/collect",
    name: "Collect",
    component: Collect,
  },
  // 我的发布
  {
    path: "/user/publish",
    name: "UserPublish",
    component: UserPublish,
  },
  {
    path: "/user/adopt",
    name: "UserAdopt",
    component: UserAdopt,
  },
  // 设置
  {
    path: "/setting",
    name: "Setting",
    component: Setting,
  },
];

const router = createRouter({
  history: createWebHashHistory(),
  scrollBehavior: () => ({
    top: 0,
  }),
  routes,
});

router.beforeEach(authGuard);

export default router;
